<?php

class File
{
    /** @var int */
    protected $id = 0;
    /** @var string */
    protected $name = '';
    /** @var string */
    protected $hash = '';
    /** @var string */
    protected $type = '';
    /** @var int */
    protected $size = 0;
    /** @var string */
    protected $time = '2000-01-01 00:00:00';
    /** @var string */
    protected $url = null;
    /** @var int */
    protected $userId = 0;

    public function getAbsoluteUrl()
    {
        return base_url($this->getUrl());
    }

    /**
     * @return User
     */
    public function getUser()
    {
        return User_Model::getUserById($this->getUserId());
    }

    public function getUserDisplayName()
    {
        $thatUser = $this->getUser();
        if ($thatUser) {
            return $thatUser->getDisplayName();
        } else {
            return '[用户不存在]';
        }
    }

    /**
     * @return array
     */
    public function getDataArray()
    {
        return array(
            'id'          => $this->getId(),
            'name'        => $this->getName(),
            'hash'        => $this->getHash(),
            'type'        => $this->getType(),
            'size'        => $this->getSize(),
            'url'         => $this->getUrl(),
            'absoluteUrl' => $this->getAbsoluteUrl(),
            'time'        => $this->getTime(),
            'userId'      => $this->getUserId(),
        );
    }

    /**
     * @return string
     */
    public function getHash()
    {
        return $this->hash;
    }

    /**
     * @param string $hash
     */
    public function setHash($hash)
    {
        $this->hash = $hash;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * @return int
     */
    public function getSize()
    {
        return $this->size;
    }

    /**
     * @param int $size
     */
    public function setSize($size)
    {
        $this->size = $size;
    }

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param string $type
     */
    public function setType($type)
    {
        $this->type = $type;
    }

    /**
     * @return string
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @param string $url
     */
    public function setUrl($url)
    {
        $this->url = $url;
    }

    /**
     * @return int
     */
    public function getUserId()
    {
        return $this->userId;
    }

    /**
     * @param int $userId
     */
    public function setUserId($userId)
    {
        $this->userId = $userId;
    }

    /**
     * @return string
     */
    public function getTime()
    {
        return $this->time;
    }

    /**
     * @param string $time
     */
    public function setTime($time)
    {
        $this->time = $time;
    }

}